package com.opta.entity;

import lombok.Data;
import org.optaplanner.core.api.domain.solution.PlanningEntityCollectionProperty;
import org.optaplanner.core.api.domain.solution.PlanningScore;
import org.optaplanner.core.api.domain.solution.PlanningSolution;
import org.optaplanner.core.api.domain.solution.drools.ProblemFactCollectionProperty;
import org.optaplanner.core.api.domain.valuerange.ValueRangeProvider;
import org.optaplanner.core.api.score.buildin.bendable.BendableScore;

import java.io.Serializable;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;

/**
 * @author GC
 * @name Solution
 * @description 解决方案
 * @date 2020/4/20 15:55
 * @since 1.0
 */
@PlanningSolution
@Data
public class OrderSolution implements Serializable {

    private String id;
    private List<TaskOrder> orders;
    private List<Line> lines;
    /**
     * 物料号可生产的班组
     * key:   物料号 materialCode
     * value: 班组   team、节拍集合
     */
    private Map<String, Map<String, Double>> materialProducibleTeamMap;

    private BendableScore score;

    /**
     * 线体产能
     * key:   lineId
     * value: 当前剩余量（初始化和供给总量相等）
     */
    private Map<String, Map<LocalDate, Integer>> lineSupplyMap;

    public OrderSolution() {
    }

    public OrderSolution(String solutionId, List<TaskOrder> orders, List<Line> lines, Map<String, Map<String, Double>> materialProducibleTeamMap, Map<String, Map<LocalDate, Integer>> lineSupplyMap) {
        this.id = solutionId;
        this.orders = orders;
        this.lines = lines;
        this.materialProducibleTeamMap = materialProducibleTeamMap;
        this.lineSupplyMap = lineSupplyMap;
    }

    @PlanningEntityCollectionProperty
    public List<TaskOrder> getOrders() {
        return orders;
    }

    @ProblemFactCollectionProperty
    @ValueRangeProvider(id = "teamRange")
    public List<Line> getLines() {
        return lines;
    }

    @PlanningScore(bendableHardLevelsSize = 1, bendableSoftLevelsSize = 2)
    public BendableScore getScore() {
        return score;
    }
}
